package cn.ybk.basic.dto;

import cn.ybk.basic.util.MD5Utils;
import cn.ybk.basic.util.StrUtils;
import cn.ybk.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

// 手机号登陆
@Data
public class PhoneDto {
    // 手机号验证码
    @NotBlank(message = "手机验证码不能为空")
    private String phoneCode;
    // 密码
    @NotBlank(message = "密码不能为空")
    private String password;
    // 确认密码
    @NotBlank(message = "确认密码不能为空")
    private String passwordRepeat;

    @NotBlank(message = "手机号码不能为空")
    private String phone;
    @NotBlank (message = "类型不能为空")
    private String type;

    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        String pwd = MD5Utils.encrypByMd5(salt + this.password);
        return User.builder()
                    .username(this.phone)
                    .state(1)
                    .createtime(new Date())
                    .password(pwd)
                    .salt(salt)
                    .phone(this.phone)
                    .build();
    }

}
